package gazpachito.examples.patterns.methodTemplate.business.vehicle;

import java.math.BigDecimal;

import org.springframework.stereotype.Component;

import gazpachito.examples.patterns.methodTemplate.api.EngineVehicleDTO;
import gazpachito.examples.patterns.methodTemplate.api.VehicleDTO;
import gazpachito.examples.patterns.methodTemplate.business.exceptions.BusinessException;
import gazpachito.examples.patterns.methodTemplate.utils.MessageUtils;

@Component("EngineVehicleBusiness")
public class EngineVehicleBusinesImpl extends
		AbstractVehicleBusinessImpl<EngineVehicleDTO> {

	@Override
	public void validateConcrete(VehicleDTO vehicle) throws BusinessException {
		// TODO Auto-generated method stub
		EngineVehicleDTO engineVehicle = (EngineVehicleDTO) vehicle;

		if (engineVehicle.getcV() == null
				|| engineVehicle.getcV().compareTo(BigDecimal.ZERO) < 0
				|| engineVehicle.getcV().compareTo(BigDecimal.ZERO) == 0) {
			throw new BusinessException(
					MessageUtils
							.getMessage(MessageUtils.ERROR_ENGINE_POWER_INCORRECT));
		}

	}

	@Override
	public void executeConcrete(VehicleDTO vehicle) {
		EngineVehicleDTO engineVehicle = (EngineVehicleDTO) vehicle;
		super.getStoredVehicles().put(engineVehicle.getIdVehicle(),
				engineVehicle);

	}

}
